package com.share;

import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * @author caifan
 * @created 2021/4/30
 * description:
 */
public class HelloWorld {
    public static void main(String[] args) {
        Flowable.just("hello").subscribe(System.out::println);
        // 输出1 到 10 每个数的平方 非并行处理
        Flowable.range(1, 10)
                .observeOn(Schedulers.computation())
                .map(v -> v * v)
                .blockingSubscribe(System.out::println);
        System.out.println("============");
        // 并行处理
        Flowable.range(1, 10)
                .flatMap(v -> Flowable.just(v)
                               .subscribeOn(Schedulers.computation())
                                .map(w -> w * w)
        )
        .blockingSubscribe(System.out::println);
        System.out.println("+======并行处理=======");
        Flowable.range(1, 10)
                .parallel()
                .runOn(Schedulers.computation())
                .map(v -> v * v)
                .sequential()
                .blockingSubscribe(System.out::println);
    }
}
